import request from "@/utils/request";
import { SubjectsQuery, SubjectsForm } from "./types";
import { AxiosPromise } from "axios";

/**
 * 科目分页数据
 *
 * @param queryParams
 */
export function getSubjectsPage(
	queryParams: SubjectsQuery
): AxiosPromise<PageResult<[]>> {
	return request({
		url: '/api/v1/subjects/page',
		method: 'get',
		params: queryParams
	});
}

/**
 * 获取店铺表单数据
 *
 * @param queryParams
 */
export function getSubjectsForm(id: number): AxiosPromise<SubjectsForm> {
	return request({
		url: '/api/v1/subjects/' + id + '/form',
		method: 'get'
	});
}

/**
 * 保存科目
 *
 * @param data
 */
export function saveSubjects(data: SubjectsForm) {
  return request({
    url: "/api/v1/subjects",
    method: "post",
    data: data,
  });
}

/**
 * 删除科目
 *
 * @param ids
 */
export function deleteSubjects(ids: string) {
	return request({
		url: '/api/v1/subjects/' + ids,
		method: 'delete'
	});
}

/**
 * 根据入账主体查出科目列表
 *
 * @param queryParams
 */
export function getSubjectsList(queryParams: SubjectsQuery): AxiosPromise<[]> {
	return request({
		url: '/api/v1/subjects/subjectsList',
		method: 'get',
		params: queryParams
	});
}

/**
 * 导入科目
 *
 * @param file
 */
export function importSubject(file: File) {
	const formData = new FormData();
	formData.append('file', file);
	return request({
		url: '/api/v1/subjects/_import',
		method: 'post',
		data: formData,
		headers: {
			'Content-Type': 'multipart/form-data'
		}
	});
}

/**
 * 导出科目
 *
 * @param queryParams
 * @returns
 */
export function exportSubject() {
	return request({
		url: '/api/v1/subjects/_export',
		method: 'get',
		responseType: 'arraybuffer'
	});
}
